package com.listen.service.DB;

import com.listen.common.*;
import com.listen.model.User;
import com.listen.vo.HeadParmsVO;
import net.sf.json.JSONObject;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 建造师选修听课考试
 * */
public class JianZaoShiXuanxiuDB8035 {
	private static final Logger log = LoggerFactory.getLogger(JianZaoShiXuanxiuDB8035.class);
	private String cookie;
	private String userid;
	private String info;
	private String urlprefix;
	private static String __viewstate="";
	private static String __viewstategenerator="C2EE9ABB";
	private static String __eventvalidation="";
	private Map<String,Object> resultMap = ConfigUtils.resultMap;
	private String __EVENTTARGET = "";
	private String __EVENTARGUMENT = "";
	private String __VIEWSTATE = "";
	private String paramid = "";
	private String[] result1;
	private String[] result2;
	private String[] result3;
	private String panduan;
	private String danxuan;
	private String duoxuan;
	private String Pwr="";
	private String Qwr="";
	private String Hwr="";
	private ConcurrentHashMap<String, Object>  msgMap = null;
	private String baseCookie = "";
	private int flag;
	private HttpClientProxy instance = new HttpClientProxy();
	private CloseableHttpResponse response = null;
	private CloseableHttpClient httpClient = null;
	private String proxyInfo = null;
	
	public static void main(String args[]) throws InterruptedException{
		JianZaoShiXuanxiuDB8035 bixiu = new JianZaoShiXuanxiuDB8035();
		IPProxyNew proxy = new IPProxyNew(null);
		String codes = "362201198008230247";
		for(String code : codes.split(",")){
			User user = new User();
			user.setCode(code);
			user.setZy("JX");
			user.setZyName("二级建造师选修");
			user.setStatus(1);//1听课，2考试
			user.setAllNum(59);
			user.setAddress("http://139.199.171.22:8035/");
			user.setPassword("888888");
			int begin=1;
			int end = 59;
			//String ip = proxy.getOneIpAndPort();
			for(int i=begin;i<=end;i++) {
				Thread.sleep(1000);
				user.setNowNum(i);
				bixiu.startListen(user,null);
			}
		}
	}

	public Map<String,Object> startListen(User user,String ip){
		this.proxyInfo = ip;
		msgMap = new ConcurrentHashMap<>();
		msgMap.put("successFlag", "0");
		msgMap.put("dayNum", "0");
		msgMap.put("addNum", "0");
		if(user.getStatus()==1)
			this.flag = 1;
		//状态为2已听完课，flag=3直接考试
		if(user.getStatus()==2)
			this.flag = 3;
		try {
			toLoginPage(user);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return msgMap;
	}
	
	//处理get方式的跳转，并解析跳转后的页面
	public void toLoginPage(User user){
		this.urlprefix = user.getAddress();
		try {
			response = instance.sendHttpGet(httpClient, urlprefix, proxyInfo);
			int state = response.getStatusLine().getStatusCode();
			if(state == 200){
				HttpEntity entity = response.getEntity();  
				String html = EntityUtils.toString(entity);
				this.setCommonParms(html);//设置登录参数
				login(user);//执行登录操作
			}else{
				print(user.getZyName()+"-"+user.getCode()+"-解析页面参数失败");
			}
		} catch (Exception e) {
			printError(user.getZyName()+"-"+user.getCode()+"-解析页面参数异常"+e);
		}finally { 
			HttpClientUtil.getInstance().closeResource(response);
        }
	}
	
	//登录
	public void login(User user){
		String code = user.getCode();
		String zyName = user.getZyName();
		Map<String, String> maps = new HashMap<String, String>();
        maps.put("__VIEWSTATE", __viewstate); 
        maps.put("__VIEWSTATEGENERATOR", __viewstategenerator);
        maps.put("__EVENTVALIDATION",__eventvalidation); 
        maps.put("txtUserName",code);
        maps.put("txtPwd",user.getPassword());
        maps.put("ddlType", "2");//学员登录 
        maps.put("btnLogin", "");
        maps.put("txtLoginName", ""); 
        maps.put("txtDM", "");
        maps.put("txtFR", ""); 
        maps.put("zhjg", "");
        maps.put("zhfr", "");
        try {
        	String url = urlprefix;
        	HeadParmsVO head = new HeadParmsVO();
	        head.setAccept("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");
	        head.setAcceptEncoding("gzip, deflate");
	        head.setAcceptLanguage("zh-CN,zh;q=0.9,en;q=0.8");
	        head.setCacheControl("max-age=0");
	        head.setConnection("keep-alive");
	        head.setHost("139.199.171.22:8035");
	        head.setOrigin("http://139.199.171.22:8035");
	        head.setReferer("http://139.199.171.22:8035/Login.aspx");
	        head.setUpgradeInsecureRequests("1");
			head.setContentType("application/x-www-form-urlencoded");
			response = instance.sendHttpPost(httpClient, head, url, maps, proxyInfo);
        	int state = response.getStatusLine().getStatusCode();
        	if(state == 302){
        		Header[] hearders = response.getHeaders("Set-Cookie");
        		String sessionId = hearders[0].getValue();
        		this.cookie = sessionId.substring(0, sessionId.indexOf(";") + 1);
        		String userIdCookie = hearders[1].getValue();
        		this.userid = userIdCookie.substring(0, userIdCookie.indexOf(";") + 1);
        		String infoCookies = hearders[2].getValue();
        		this.info = infoCookies.substring(0, infoCookies.indexOf(";"));
        		this.baseCookie = cookie + userid + info;
        		if(flag==3){//只考试
        			buildPaper(user);
        		}else if(flag < 3){
        			shipinSection(user);
        			//updateVidoSate(user);//听课，考试
        		}else{
        			print(zyName+"-"+code+"-登录成功后跳转标识异常-flag="+flag);
        			logout(user);
        		}
        	}else{
        		print(zyName+"-"+code+"-登录失败--->"+state);
        		logout(user);
        	}
		} catch (Exception e) {
			printError(zyName+"-"+code+"-登录异常--->"+e);
		}
	}

	public void shipinCurStudy(User user){
		String url = this.urlprefix + "StudentClass/shipinCurStudy.aspx";
		String cookie = user.getCookie();
		HeadParmsVO head = new HeadParmsVO();
		head.setAccept("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");
		head.setAcceptEncoding("gzip, deflate");
		head.setAcceptLanguage("zh-CN,zh;q=0.9,en;q=0.8");
		head.setCacheControl("max-age=0");
		head.setConnection("keep-alive");
		head.setCookie(cookie);
		head.setHost("139.199.171.22:8035");
		head.setOrigin("http://139.199.171.22:8035");
		head.setReferer("http://139.199.171.22:8035/StudentClass/SMN_VIP.aspx");
		head.setUpgradeInsecureRequests("1");
		head.setContentType("application/x-www-form-urlencoded");
		try {
			response = instance.sendHttpGet(httpClient, head, url, null);
			int state = response.getStatusLine().getStatusCode();
			if (state == 200) {
				shipinSection(user);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	private void shipinSection(User user) {
		String zyName = user.getZyName();
		int i = user.getNowNum();
		String shipinSection_url = user.getAddress() + "/StudentClass/shipinSection.aspx";
		user.setReferer(shipinSection_url);
		String cookie = this.baseCookie;
		HeadParmsVO heads = new HeadParmsVO();
		heads.setAccept("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
		heads.setCookie(cookie);
		heads.setUpgradeInsecureRequests("1");
		try {
			response = instance.sendHttpGet(httpClient,heads, shipinSection_url,proxyInfo);
			int state = response.getStatusLine().getStatusCode();
			if(state == 200){
				HttpEntity entity = response.getEntity();
				String html = EntityUtils.toString(entity);
				Document document = Jsoup.parse(html);
				Element parm1 = document.getElementById("__VIEWSTATE");
				__VIEWSTATE = parm1.attr("value");
				Element parm2 = document.getElementById("__VIEWSTATEGENERATOR");
				__viewstategenerator = parm2.attr("value");
				shipinSectionPost(user);
			}else{
				print(zyName+"-"+ user.getCode() +" 第"+i +"个视频,shipinSection-->方法请求失败:"+state);
			}
		}catch(Exception e) {
			logout(user);
		}finally {
			HttpClientUtil.getInstance().closeResource(response);
		}
	}

	//开始学习
	/*private void checkCanWatch(User user) {
		int i = user.getNowNum();
		this.paramid = i < 10 ? "0000"+i : "000"+i;
		String params = "{Vcode:\"" + paramid + "\"}";
		String checkCanWatch_url = user.getAddress() + "/StudentClass/shipinSection.aspx/CheckCanWatch?dt="+ DateFormatUtil.getDateEN(new Date());
		HeadParmsVO heads = new HeadParmsVO();
		heads.setCookie(baseCookie);
		heads.setReferer(user.getReferer());
	    heads.setAccept("application/json, text/javascript, ; q=0.01");
	    heads.setAcceptEncoding("gzip, deflate");
	    heads.setAcceptLanguage("zh-CN,zh;q=0.9");
	    heads.setContentType("application/json; charset=UTF-8");
	    heads.setxRequestedWith("XMLHttpRequest");
    	heads.setUpgradeInsecureRequests("1");
    	heads.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36");
    	
		user.setReferer(checkCanWatch_url);//设置referer
		try {
			response = instance.sendHttpPost(httpClient, heads, checkCanWatch_url, params,proxyInfo);
			int state = response.getStatusLine().getStatusCode();
			if(state == 200){
				shipinSectionPost(user);
			}else{
				print(user.getZyName()+"-"+ user.getCode() +" 第"+i +"个视频,-checkCanWatch-->请求失败:"+state);
			}
		} catch (Exception e) {
			logout(user);
		}finally {
			HttpClientUtil.getInstance().closeResource(response);
		}
	}*/
		
	public void shipinSectionPost(User user) {
		String shipinSectionPost_url = user.getAddress() + "/StudentClass/shipinSection.aspx";
		
		HeadParmsVO heads = new HeadParmsVO();
	    heads.setAccept("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
	    heads.setAcceptEncoding("gzip, deflate");
	    heads.setAcceptLanguage("zh-CN,zh;q=0.9");
	    heads.setContentType("application/x-www-form-urlencoded");
	    heads.setxRequestedWith("XMLHttpRequest");
	    heads.setCookie(this.baseCookie);
    	heads.setReferer(user.getReferer());
    	heads.setUpgradeInsecureRequests("1");
    	heads.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36");
    	
    	int classNo = user.getNowNum();
    	Map<String, String> maps = new HashMap<String, String>();
    	maps.put("__EVENTTARGET", this.__EVENTTARGET);
		maps.put("__EVENTARGUMENT", this.__EVENTARGUMENT);
        maps.put("__VIEWSTATE", this.__VIEWSTATE);
        maps.put("__VIEWSTATEGENERATOR",__viewstategenerator);
        maps.put("dr1","-1");
        
        user.setReferer(shipinSectionPost_url);
        for(int k=0;k<10;k++) {
        	String key = "rep1$ctl0"+ k +"$hdOrders";
        	maps.put(key, "1");
    		if(classNo%10 != 0) {
    			if((k+1)==(classNo%10)) {
    				maps.put("rep1$ctl0"+k+"$Button1", "进入听课");
    			}
    		}else {
    			if(k == 9) {
    				maps.put("rep1$ctl09$Button1", "进入听课");
    			}
    		}
        }
        try {
        	response = instance.sendHttpPost(httpClient, heads, shipinSectionPost_url, maps, proxyInfo);
        	int status = response.getStatusLine().getStatusCode();
    		if(status == 200) {
    			this.updateVidoSate(user);
    		}else {
    			print(user.getZyName()+"-"+user.getCode() +"-第"+classNo+"个视频-shipinSection-post--> 请求成功"+status);
    		}
		} catch (Exception e) {
			print(user.getZyName()+"-"+user.getCode() +"-第"+ classNo +"个视频-shipinSection-post--> 请求异常"+e);
		}finally {
			instance.closeResource(response, httpClient);
		}
	}
	
	//听课，修改视频状态
	public void updateVidoSate(User user){
		String code = user.getCode();
		String zyName = user.getZyName();
		int i = user.getNowNum();
		try {
			String Start = DateFormatUtil.getDateAnyMinuteBeforeStr(0);
			Start = Start.replaceAll(" ", "+").replaceAll(":", "%3a");
			String uid = this.userid.substring(userid.indexOf("=")+1, userid.length()-1);
			String id = i < 10 ? "0000" + i : "000" + i;
			String parms = "{\"RVCode\":\"" + i + "\"}";
			String cookie = this.baseCookie +";http://139.199.171.22:8035/StudentClass/WatchVideo.aspx?ids="+ id +";totaltime=2281; checkUid="+uid+"; nowtime=2281;Start="+Start+";id="+id;
			String updateUrl = this.urlprefix + "/StudentClass/WatchVideo.aspx/UpdateStudyType?dt="
					+ DateFormatUtil.getDateEN(new Date());
			
			HeadParmsVO heads = new HeadParmsVO();
			heads.setAccept("application/json, text/javascript, */*; q=0.01");
			heads.setxRequestedWith("XMLHttpRequest");
			heads.setHost("139.199.171.22:8035");
			heads.setOrigin("http://139.199.171.22:8035");
			heads.setReferer("http://139.199.171.22:8035/StudentClass/WatchVideo.aspx?ids=00001");
			heads.setContentType("application/json;utf-8");
			heads.setCookie(cookie);
			response = instance.sendHttpPost(httpClient, heads, updateUrl, parms, proxyInfo);
			int state = response.getStatusLine().getStatusCode();
			String entityStr = EntityUtils.toString(response.getEntity(), "UTF-8");
			String msg = (String) JSONObject.fromObject(entityStr).get("d");
			if(state == 200){
				System.out.println(msg);
				ss(user);
			}else{
				print(zyName+"-"+ code +"-第"+i +"个视频播放失败!"+msg);
			}
		} catch (Exception e) {
			e.printStackTrace();
			printError(zyName+"-"+ code +" 第"+i +"个视频"+e);
		}finally{
			instance.closeResource(response, httpClient);
		}
		if(flag==2)//听课并考试
			buildPaper(user);
		else//只听课，听完退出登录
			logout(user);
	}
	
	//听课，修改视频状态
	public void ss(User user){
		String code = user.getCode();
		String zyName = user.getZyName();
		int index=0;
		String urls = "";
		int i = user.getNowNum();
		try {
			int number = (int)(40+Math.random()*(60-40+1));
			String Start = DateFormatUtil.getDateAnyMinuteBeforeStr(number);
			Start = Start.replaceAll(" ", "+").replaceAll(":", "%3a");
			index = i < 57 ? i : i+4;
			String uid = this.userid.substring(userid.indexOf("=")+1, userid.length()-1);
			String parms = "{\"classid\":\"" + index + "\",\"uid\":\""+ uid +"\"}";
			String cookie = this.cookie + this.userid + this.info +";totaltime=2281; checkUid="+uid+"; nowtime=2281;Start="+Start;
			urls = this.urlprefix+"/EntpClass/Example.aspx/ss";
			
			HeadParmsVO heads = new HeadParmsVO();
			heads.setAccept("*/*");
			heads.setxRequestedWith("XMLHttpRequest");
			heads.setContentType("application/json;utf-8");
			heads.setCookie(cookie);
			response = instance.sendHttpPost(httpClient, heads, urls, parms, proxyInfo);
			int state = response.getStatusLine().getStatusCode();
			String entityStr = EntityUtils.toString(response.getEntity(), "UTF-8");
			String msg = (String) JSONObject.fromObject(entityStr).get("d");
			if(state == 200){
				msgMap.put("successFlag", "1");
				msgMap.put("addNum", "1");
				if("进度更新完毕，请看下个视频".equals(msg) || "课程全部看完，可以进行考试".equals(msg)){
					msgMap.put("dayNum", "1");
				}
				if(user.getAllNum() == i){
					user.setStatus(2);
				}
				print(zyName+"-"+ code +"-第"+i +"个视频"+msg);
			}else{
				print(zyName+"-"+ code +"-第"+i +"个视频播放失败!"+msg);
			}
			Thread.sleep(1000*1);
		} catch (Exception e) {
			e.printStackTrace();
			printError(zyName+"-"+ code +" 第"+i +"个视频"+e);
		}finally{
			instance.closeResource(response, httpClient);
		}
		if(flag==2)//听课并考试
			buildPaper(user);
		else//只听课，听完退出登录
			logout(user);
			
	}

	//生成试卷
	public void buildPaper(User user){
		try {
			//第一步：生成试卷
			String path = this.urlprefix+"/TR_TestPaper.aspx";
			String st = DateFormatUtil.getDateAnyMinuteBeforeStr(50);
			st = st.replaceAll(" ", "+").replaceAll(":", "%3a");
			String cookie = this.cookie + this.userid + this.info+";Start="+st+";id=00001";
			HeadParmsVO heads = new HeadParmsVO();
	        heads.setAccept("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
	        heads.setCookie(cookie);
			response = instance.sendHttpGet(httpClient, heads,path, proxyInfo);
	        int state = response.getStatusLine().getStatusCode();
			if(state == HttpStatus.SC_OK){
				//第二步：解析HTML,获取题目id
				HttpEntity entity = response.getEntity();  
				String html = EntityUtils.toString(entity);
			    Document document = Jsoup.parse(html);
			    Element parm1 = document.getElementById("_thid");
			    this.panduan = parm1.attr("value");
			    Element parm2 = document.getElementById("Hidden1");
			    this.danxuan = parm2.attr("value");
			    Element parm3 = document.getElementById("Hidden2");
			    this.duoxuan = parm3.attr("value");
			    this.result1 = (panduan.substring(0, panduan.length()-1)).split(",");
			    this.result2 = (danxuan.substring(0, danxuan.length()-1)).split(",");
			    this.result3 = (duoxuan.substring(0, duoxuan.length()-1)).split(",");
			    //提交试卷
			    testOnline(user);
			}else{
				print(user.getZyName()+"-"+user.getCode()+"-生成试卷失败--->"+state);
			}
		}catch(Exception e){
			printError(user.getZyName()+"-"+user.getCode()+"-生成试卷异常--->"+e);
		}finally {
			instance.closeResource(response, httpClient);
			
		}
		
	}
	//提交试卷
	public void testOnline(User user){
		String code = user.getCode();
		String zyName = user.getZyName();
		try {
			//设置答案
			this.setParmsValue();
			String cookie = this.cookie + this.userid + this.info;
	        List<NameValuePair> params = new ArrayList<NameValuePair>();  
	        params.add(new BasicNameValuePair("Pid", this.panduan));  
	        params.add(new BasicNameValuePair("Qid", this.danxuan));
	        params.add(new BasicNameValuePair("Hid",this.duoxuan));  
	        params.add(new BasicNameValuePair("Pwr",this.Pwr));  
	        params.add(new BasicNameValuePair("Qwr",this.Qwr));  
	        params.add(new BasicNameValuePair("Hwr", this.Hwr));
	        params.add(new BasicNameValuePair("AlNums", "0"));
	        
	        /*System.out.println("判断题="+panduan);
			System.out.println("单选题="+danxuan);
			System.out.println("多选题="+duoxuan);*/
			
	        //要传递的参数.  
	        String url = this.urlprefix+"/MarkTJ.aspx?" + URLEncodedUtils.format(params,"UTF-8");
	        HeadParmsVO heads = new HeadParmsVO();
	        heads.setAccept("*/*");
	        heads.setCookie(cookie);
	        heads.setxRequestedWith("XMLHttpRequest");
	        response = instance.sendHttpGet(httpClient, heads,url, proxyInfo);
	        int state = response.getStatusLine().getStatusCode();
	        if (state == HttpStatus.SC_OK) {  
                HttpEntity entity = response.getEntity();
                String resultStr = EntityUtils.toString(entity, "UTF-8");
                System.out.println("返回结果:"+resultStr);
                String score = resultStr.substring(0,resultStr.indexOf("|"));
                print(zyName+"-"+ code +"-考试成功，本次考试成绩为："+score+"分");
                msgMap.put("successFlag", "1");
                user.setStatus(3);
            }else{
            	print(zyName+"-"+ code +"-试卷提交失败！------->state="+state);
            }
		} catch (Exception e) {
			printError(zyName+"-"+code+"-生成试卷异常--->"+e);
		}finally {
			instance.closeResource(response, httpClient);
		}
		//退出登录
		logout(user);
	}
		
	//退出登录
	public void logout(User user){
		try {
			String path = this.urlprefix+"/Public/Logout.aspx";
			String cookie = this.cookie + this.userid + this.info +"totaltime=2281; checkUid=38060; nowtime=2281";
			HeadParmsVO heads = new HeadParmsVO();
			heads.setAccept("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
			heads.setCookie(cookie);
			response = instance.sendHttpGet(httpClient, heads, path,proxyInfo);
			int state = response.getStatusLine().getStatusCode();
			if(state == 200 || state == 302){
				//System.out.println("退出登录成功");
				//print("退出登录成功!");
			}else{
				//System.out.println("退出登录失败!");
				//print("退出登录失败!");
			}
		} catch (Exception e) {
			System.out.println("退出登录异常--->");
			e.printStackTrace();
		}finally{
			instance.closeResource(response, httpClient);
		}
	}
	
	//设置登录参数
	public void setCommonParms(String html){
		Document document = Jsoup.parse(html);
	    Element parm1 = document.getElementById("__VIEWSTATEGENERATOR");
	    __viewstategenerator = parm1.attr("value");
	    Element parm2 = document.getElementById("__EVENTVALIDATION");
	    __eventvalidation = parm2.attr("value");
	    Element parm3 = document.getElementById("__VIEWSTATE");
	    __viewstate = parm3.attr("value");
	    /*System.out.println("__viewstategenerator="+__viewstategenerator);
	    System.out.println("__eventvalidation="+__eventvalidation);
	    System.out.println("__viewstate="+__viewstate);*/
	}
	
	private void setParmsValue(){
		//设置判断题答案
		for(int i=0;i<this.result1.length;i++){
			String pid = this.result1[i];
			String panswer = (String) this.resultMap.get(pid);
			if(!"Yes".equalsIgnoreCase(panswer)&&!"No".equalsIgnoreCase(panswer)){
				panswer = "Yes";
			}
			if(i==0)
				Pwr = panswer;
			else
				Pwr = Pwr + "," + panswer;
		}
		this.Pwr = this.Pwr + ",";
		
		//设置单选题答案
		for(int i=0;i<this.result2.length;i++){
			String pid = this.result2[i];
			String panswer = (String) resultMap.get(pid);
			if(!"A".equalsIgnoreCase(panswer)&&!"B".equalsIgnoreCase(panswer)
					&&!"C".equalsIgnoreCase(panswer)&&!"D".equalsIgnoreCase(panswer)){
				panswer = "A";
			}
			if(i==0){
				Qwr = panswer;
			}else{
				Qwr = Qwr + "," + panswer;
			}
				
		}
		this.Qwr = Qwr + ",";
		//设置多选题答案
		for(int i=0;i<this.result3.length;i++){
			String pid = this.result3[i];
			String panswer = (String) resultMap.get(pid);
			if(panswer==null || panswer.trim().length()!=9){
				panswer = "A|B|C|D|0";
			}
			if(i==0)
				Hwr = panswer;
			else
				Hwr = Hwr + "," + panswer;
		}
		this.Hwr = Hwr + ",";
		/*System.out.println("Pwr="+Pwr);
		System.out.println("Qwr="+Qwr);
		System.out.println("Hwr="+Hwr);*/
	}
	
	private void print(String msg){
		msgMap.put("msg", msg);
		log.info(msg);
	}
	
	private void printError(String errMsg){
		msgMap.put("errMsg", errMsg);
		log.error(errMsg);
	}
}
